package com.glela.ningchongqing;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;

import com.alibaba.fastjson.JSONObject;

public class 分类测试 {
//	public final static String url = "http://api.xzhuang.com/v2/yg_platform/";
//	public final static String url = "http://api.test.xzhuang.com/yg_platform/";
//	public final static String url = "http://api.dev.xzhuang.com/yg_platform/";
//	public final static String url = "http://localhost:8080/yg_platform/";
//	public final static String url = "http://192.168.0.33:8080/yg_platform/";
	public final static String url = "http://192.168.50.123:8080/yg_platform/";

	public static void main(String[] args) {
//		goodsClassifyList();
//		thirdGoodsClassifyList();
//		thirdGoodsClassifyGoodsList();
//		initSearch();
//		goodsInfoPreview();
//		serialGoodsPreview();
//		zone();
//		branchBankList();
//		newGoodsEsSearch();
		esGlobalSearch();
	}
	
	public static void esGlobalSearch() {
		JSONObject jo = new JSONObject();
		jo.put("searchKeyWord", "化妆棉");
		jo.put("type", 1);
		jo.put("pageNum", 1);
		jo.put("pageSize", 10);
		try {
			String post = doPost(jo.toJSONString(), url + "search/esGlobalSearch","application/json");
			System.out.println("esGlobalSearch========"+post);
		} catch (Exception e) {
			System.out.println("esGlobalSearch------------"+e.getMessage());
		}
	}
	
	public static void newGoodsEsSearch() {
		JSONObject jo = new JSONObject();
		jo.put("searchKeyWord", "化妆棉");
		jo.put("pageNum", 1);
		jo.put("pageSize", 10);
		try {
			String post = doPost(jo.toJSONString(), url + "search/newGoodsEsSearch","application/json");
			System.out.println("newGoodsEsSearch========"+post);
		} catch (Exception e) {
			System.out.println("newGoodsEsSearch------------"+e.getMessage());
		}
	}
	
	public static void branchBankList() {
		JSONObject jo = new JSONObject();
		jo.put("bankId", 1);
		jo.put("cityId", 1255);
		try {
			String post = doPost(jo.toJSONString(), url + "userAddress/branchBankList","application/json");
			System.out.println("branchBankList========"+post);
		} catch (Exception e) {
			System.out.println("branchBankList------------"+e.getMessage());
		}
	}
	
	public static void zone() {
		JSONObject jo = new JSONObject();
		jo.put("zongLevel", 3);
		jo.put("parentId", 1280);
		try {
			String post = doPost(jo.toJSONString(), url + "userAddress/zone","application/json");
			System.out.println("zone========"+post);
		} catch (Exception e) {
			System.out.println("zone------------"+e.getMessage());
		}
	}
	
	public static void serialGoodsPreview() {
		JSONObject jo = new JSONObject();
		jo.put("serialId", "84");
		jo.put("pageNum", 1);
		jo.put("pageSize", 10);
		try {
			String post = doPost(jo.toJSONString(), url + "serialGood/serialGoodsPreview","application/json");
			System.out.println("serialGoodsPreview========"+post);
		} catch (Exception e) {
			System.out.println("serialGoodsPreview------------"+e.getMessage());
		}
	}
	
	public static void goodsInfoPreview() {
		JSONObject jo = new JSONObject();
		jo.put("goodId", "510");
		try {
			String post = doPost(jo.toJSONString(), url + "goods/goodsInfoPreview","application/json");
			System.out.println("goodsInfoPreview========"+post);
		} catch (Exception e) {
			System.out.println("goodsInfoPreview------------"+e.getMessage());
		}
	}
	
	public static void goodsClassifyList() {
		JSONObject jo = new JSONObject();
		try {
			String post = doPost(jo.toJSONString(), url + "classify/goodsClassifyList","application/json");
			System.out.println("goodsClassifyList========"+post);
		} catch (Exception e) {
			System.out.println("goodsClassifyList------------"+e.getMessage());
		}
	}
	
	public static void thirdGoodsClassifyList() {
		JSONObject jo = new JSONObject();
		jo.put("id", "56");
		try {
			String post = doPost(jo.toJSONString(), url + "classify/thirdGoodsClassifyList","application/json");
			System.out.println("thirdGoodsClassifyList========"+post);
		} catch (Exception e) {
			System.out.println("thirdGoodsClassifyList------------"+e.getMessage());
		}
	}
	
	public static void thirdGoodsClassifyGoodsList() {
		JSONObject jo = new JSONObject();
		jo.put("ids", "78");
		jo.put("pageNum", 1);
		jo.put("pageSize", 10);
		try {
			String post = doPost(jo.toJSONString(), url + "classify/thirdGoodsClassifyGoodsList","application/json");
			System.out.println("thirdGoodsClassifyGoodsList========"+post);
		} catch (Exception e) {
			System.out.println("thirdGoodsClassifyGoodsList------------"+e.getMessage());
		}
	}

	public static void initSearch() {
		JSONObject jo = new JSONObject();
		jo.put("type", 1);
		try {
			String post = doPost(jo.toJSONString(), url + "search/initSearch","application/json");
			System.out.println("initSearch========"+post);
		} catch (Exception e) {
			System.out.println("initSearch------------"+e.getMessage());
		}
	}
	
	public static String doPost(String content,String url,String contentType) throws IOException {
		StringBuilder result = new StringBuilder();
        URL postUrl = new URL(url);  
        URLConnection con = postUrl.openConnection(); 
        con.setConnectTimeout(5000);
        con.setDoOutput(true);  
        con.setRequestProperty("Pragma", "no-cache");  
        con.setRequestProperty("Cache-Control", "no-cache"); 
        if(contentType!=null)
        {
        	con.setRequestProperty("Content-Type", contentType);  
        }
        OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream());    
        out.write(new String(content.getBytes("UTF-8")));  
        out.flush();  
        out.close();  
        BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));  
        String line = "";  
        for (line = br.readLine(); line != null; line = br.readLine()) {  
        	result = result.append(line);
        }  
		return result.toString();
	}
}
